﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Uranus.Common
{
    public class VerifyCommon
    {   static  Random random = new Random();
        /// <summary>
        /// 获取邮箱验证内容
        /// </summary>
        /// <param name="url"></param>
        /// <param name="email"></param>
        /// <param name="guid"></param>
        /// <returns></returns>
        public static string GetEmailContent(string url,string email,string guid,string name)
        {
            string content = GetEncode(guid, 100);
            return string.Format("<div style='width:600px;margin:auto;line-height:2;font-size:12px;overflow:hidden;border-radius:3px;background:#FFF;box-shadow:0 0 10px rgba(0, 0, 0, 0.2);'><div style='height:60px;border-radius:3px 3px 0 0;background:#ff6600;'><span style='float:left;width:210px;height:33px;padding:5px 16px 0 10px;'></span><span style='display:block;width:325px;padding-top:15px;line-height:31px;font-size:14px;font-weight:bold;color:#FFF;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;'>激活大同行邮箱</span></div><div style='padding:15px 30px;word-wrap:break-word;border:solid #C5C5C5;border-width:0 1px;'><br  /><div style='line-height:28px;font-size:14px;font-weight:bold;'>你好！感谢你激活大同行。</div><p>你申请绑定的邮箱为："+email+"，大同行帐号为"+name+"。</p><p>为激活帐号，请单击以下链接。</p><p><a href='" + url + "?id=" + content + "'>点击此处立即激活你的帐号</a><span style='color:#999;'></span></p><p>如果上面链接无法打开，请复制以下链接至浏览器上 "+url+"?id="+content+"</p><br  /><p style='color:#999;'>此信是由 <a href='http://www.dtcash.com' target='_blank'>www.dtcash.com</a> 系统发出，系统不接收回信，请勿直接回复。如有任何疑问请<a href='mailto:webmaster@dtcash.com' target='_blank'>联系我们</a>。</p></div><div style='height:10px;overflow:hidden;border:1px solid #C5C5C5;border-top:0 none;border-radius:0 0 3px 3px;'><img src='http://115.com/static/email/mail_bottom.gif' style='display:block;'  /></div></div>");
        }
        private static string GetEncode(string str, int total)
        {
            string str1 = "1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm";
            StringBuilder stringBuilder = new StringBuilder();
            //Console.WriteLine(str1.Length);
            for (int j = 0; j < total; j++)
            {
                stringBuilder.Append(str1[random.Next(0, 62)]);
            }
            stringBuilder.Append(str);
            for (int j = 0; j < total; j++)
            {
                stringBuilder.Append(str1[random.Next(0, 62)]);
            }
            return stringBuilder.ToString();
        }
        /// <summary>
        /// 邮箱验证解码
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public static string DnCodeEmailCotent(string content)
        {
            if (content.Length != 236)
            {
                return "";
            }
            else
            {
                return content.Substring(100, content.Length - 200);
            }
        }
        //短信码
        public static string GetNoteCode()
        {
            return random.Next(10000, 99999).ToString();
        }
        /// <summary>
        /// 获取邮箱修改验证内容
        /// </summary>
        /// <param name="url"></param>
        /// <param name="name"></param>
        /// <param name="guid"></param>
        /// <returns></returns>
        public static string GetEmailChangeContent(string url, string name, string guid)
        {
            string content = GetEncode(guid, 100);
            return string.Format("<div style='width:600px;margin:auto;line-height:2;font-size:12px;overflow:hidden;border-radius:3px;background:#FFF;box-shadow:0 0 10px rgba(0, 0, 0, 0.2);'><div style='height:60px;border-radius:3px 3px 0 0;background:#ff6600;'><span style='float:left;width:210px;height:33px;padding:5px 16px 0 10px;'></span><span style='display:block;width:325px;padding-top:15px;line-height:31px;font-size:14px;font-weight:bold;color:#FFF;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;'>大同行密码修改</span></div><div style='padding:15px 30px;word-wrap:break-word;border:solid #C5C5C5;border-width:0 1px;'><br  /><div style='line-height:28px;font-size:14px;font-weight:bold;'>东家 "+name+" 您好！</div><p>你申请修改密码（20分钟内链接有效）</p><p>请单击以下链接。</p><p><a href='" + url + "?id=" + content + "'>点击修改密码</a><span style='color:#999;'></span></p><p>如果上面链接无法打开，请复制以下链接至浏览器上 "+url+"?id="+content+"</p><br  /><p style='color:#999;'>此信是由 <a href='http://www.dtcash.com' target='_blank'>www.dtcash.com</a> 系统发出，系统不接收回信，请勿直接回复。如有任何疑问请<a href='mailto:webmaster@dtcash.com' target='_blank'>联系我们</a>。</p></div><div style='height:10px;overflow:hidden;border:1px solid #C5C5C5;border-top:0 none;border-radius:0 0 3px 3px;'><img src='http://115.com/static/email/mail_bottom.gif' style='display:block;'  /></div></div>");
        }

    }
}
